/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */
package com.yami.shop.groupbuy.common.listener;

import com.yami.shop.bean.enums.OrderType;
import com.yami.shop.bean.event.PaySuccessOrderEvent;
import com.yami.shop.bean.order.PaySuccessOrderOrder;
import com.yami.shop.groupbuy.common.service.GroupPayService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 团购支付回调
 *
 * @author Yami
 */
@Component("groupPaySuccessListener")
@AllArgsConstructor
public class PaySuccessOrderListener {

    private GroupPayService groupPayService;

    /**
     * 团购支付成功回调
     */
    @EventListener(PaySuccessOrderEvent.class)
    @Order(PaySuccessOrderOrder.GROUPON)
    public void grouponPaySuccessListener(PaySuccessOrderEvent event) {
        List<com.yami.shop.bean.model.Order> orders = event.getOrders();

        for (com.yami.shop.bean.model.Order order : orders) {
            if (!Objects.equals(order.getOrderType(), OrderType.GROUP.value())) {
                continue;
            }
            // 支付成功回调通知处理
            groupPayService.paySuccessNoticeHandle(order);
        }

    }
}
